//
//  MyAccountViewController.m
//  NiuBanJin
//
//  Created by Billy on 15/10/10.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "MyAccountViewController.h"
#import "DepositViewController.h"
#import "SafeCentreViewController.h"
#import "RollOutViewController.h"
#import "IncomeViewController.h"
#import "AssetDetailsViewController.h"
#import "TicketsViewController.h"
#import "ExchangeAndScoreHistoryController.h"
#import "IDCardAuthenticationViewController.h"
#import "BankCardBindingViewController.h"
#import "WalletCenterView.h"
#import "TicketExcahngeAndSigningController.h"

@interface MyAccountViewController ()<UITableViewDataSource , UITableViewDelegate , WalletCenterViewDelegate>

@property (nonatomic , strong) NSArray *array_assetText;
@property (nonatomic , strong) NSArray *array_assetNumber;//存放资金数据
@property (nonatomic,  strong) NSMutableDictionary *mutableDictionary_data;
@property(nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *mutableArray_dataForTableView; //tableview数据源
@property (nonatomic , assign) NSInteger defaultTag;

@end

@implementation MyAccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self pageSettingsAndSubviewsCreation];
   }

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = NO;
    [self getDataFromServer];
}

#pragma  mark - data prepation
- (void) getDataFromServer {
    
    
    NSDictionary *dic_params = @{@"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId),@"token":GETCURRENTUSERINOBYPRAMETERES(user_userToken)};
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrGetUserAssetsByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            
            if ([dic_result[@"status"] integerValue] == 0) { //正确得到数据
                
                [self.mutableArray_dataForTableView removeAllObjects]; //去掉历史数据
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"dayWalletProfit"] forKey:@"dayWalletProfit"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"asset"] forKey:@"asset"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"totalPayoff"] forKey:@"totalPayoff"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"usableAseet"] forKey:@"assertUseable"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"assetFrozen"] forKey:@"assetFrozen"];
                 [self.mutableDictionary_data setObject:dic_result[@"result"][@"realname"] forKey:@"realname"];
                
                [self.mutableArray_dataForTableView addObject:@"list"];
                [ self.mutableArray_dataForTableView  addObject:dic_result[@"result"][@"tickets"] ];
                [self.mutableArray_dataForTableView addObject:dic_result[@"result"][@"scores"]];
            }else {
                
                [UsefulUtil showAlertView:dic_result[@"msg"]];
            }
            if ([self.mutableDictionary_data count] > 0) {
                
                //update UI
                
                [self updateUI];
            }
        }else {
            
            [UsefulUtil showAlertView:error.description];
        }
    }];
 
}


- (void) updateUI {
    
    // 欢迎
    
   UILabel *label_userPhoneNumber = [[self.view viewWithTag:49] viewWithTag:51];
 
    if ([self.mutableDictionary_data[@"realname"] isEqualToString:@""]) {
        
        [label_userPhoneNumber setText: GETCURRENTUSERINOBYPRAMETERES(user_userName)];
    }else {
        
        [label_userPhoneNumber setText: [NSString stringWithFormat:@"亲爱的用户:%@,您好" ,self.mutableDictionary_data[@"realname"]]];
    }
    
    // 用户总资产
    UILabel *label_asset = [[self.view viewWithTag:49] viewWithTag:50];
    
    if (self.mutableDictionary_data[@"asset"]) {
        
        [label_asset setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"asset"]]];
    }
    
    //今日收益

    if (self.mutableDictionary_data[@"dayWalletProfit"]) {
        
        UILabel *label_totalProfit = [[self.view viewWithTag:400] viewWithTag:11];
        
        [label_totalProfit setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"dayWalletProfit"]]];
    }

    
    
    //累计收益
    
    if (self.mutableDictionary_data[@"totalPayoff"]) {
        
        UILabel *label_totalProfit = [[self.view viewWithTag:401] viewWithTag:11];
        
        [label_totalProfit setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"totalPayoff"]]];
    }
    
    // 可用余额
    
    if (self.mutableDictionary_data[@"assertUseable"]) {
        
        UILabel *label_totalProfit = [[self.view viewWithTag:402] viewWithTag:11];
        
        [label_totalProfit setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"assertUseable"]]];
    }
    
    //冻结金额
   
    if (self.mutableDictionary_data[@"assetFrozen"]) {
        
       UILabel *label_totalProfit = [[self.view viewWithTag:403] viewWithTag:11];
        
        [label_totalProfit setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"assetFrozen"]]];
    }
    
    
    // 按要求账户明细也有动画
    NSIndexPath *indexPath_asset = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView reloadRowsAtIndexPaths:@[indexPath_asset] withRowAnimation:YES];
    
    // 有多少加息券
    
    NSIndexPath *indexPath_ticket = [NSIndexPath indexPathForRow:1 inSection:0];
    
    [self.tableView reloadRowsAtIndexPaths:@[indexPath_ticket] withRowAnimation:YES];
    
    // 有多少积分
    
    NSIndexPath *indexPath_score = [NSIndexPath indexPathForRow:2 inSection:0];
                              
    [self.tableView reloadRowsAtIndexPaths:@[indexPath_score] withRowAnimation:YES];
}


#pragma mark - depositAcion存入
- (void)depositAcion {

    if ([UserManager sharedUserManager].isAuthentication == 0) {
        
        IDCardAuthenticationViewController *IDVC = [[IDCardAuthenticationViewController alloc]init];
        IDVC.Type = 0;
        [IDVC setHidesBottomBarWhenPushed:YES];
        
        [self.navigationController pushViewController:IDVC animated:YES];
    }else {
        if ([UserManager sharedUserManager].isCardBinding == 0) {
            BankCardBindingViewController *bankBindingVC = [[BankCardBindingViewController alloc]init];

            [bankBindingVC setHidesBottomBarWhenPushed:YES];
        
            [self.navigationController pushViewController:bankBindingVC animated:YES];
        }else {
            
            DepositViewController *depositVC = [[DepositViewController alloc]init];
            [depositVC setHidesBottomBarWhenPushed:YES];
            
            [self.navigationController pushViewController:depositVC animated:YES];
        }
    }
}
#pragma  mark -rollOutAcion转出

- (void)rollOutAcion {
    
    if ([UserManager sharedUserManager].isAuthentication == YES) {
        //是否实名认证
        if ([UserManager sharedUserManager].isCardBinding == YES) {
            //是否绑卡
            RollOutViewController *rollOutVC = [[RollOutViewController alloc]init];
            
            [rollOutVC setHidesBottomBarWhenPushed:YES];
            
            [self.navigationController pushViewController:rollOutVC animated:YES];
        }else {
            //去绑卡
            BankCardBindingViewController *bankBindingVC = [[BankCardBindingViewController alloc]init];
            
            [bankBindingVC setHidesBottomBarWhenPushed:YES];
            
            [self.navigationController pushViewController:bankBindingVC animated:YES];
        }
       
    }else {
        //去实名认证
        IDCardAuthenticationViewController *IDVC = [[IDCardAuthenticationViewController alloc]init];
        IDVC.Type = 0;
        [IDVC setHidesBottomBarWhenPushed:YES];
        
        [self.navigationController pushViewController:IDVC animated:YES];
    }
}
#pragma mark -numberOfRowsInSection

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([self.mutableArray_dataForTableView count] > 0) {
        
        return [self.mutableArray_dataForTableView count];
    }else  {
        
        return 3;
    }
}

#pragma mark -viewForFooterInSection

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]init];
    
    view.backgroundColor = [UIColor whiteColor];
    
    return view;
    
}
#pragma mark -cellForRowAtIndexPath

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *cellId = @"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:15.0];
    cell.detailTextLabel.textColor = [UsefulUtil colorWithHexString:@"#989898"];
    cell.accessoryType = YES;
    if (indexPath.row == 0) {
    
    cell.imageView.image = [UIImage imageNamed:@"account_detail.png"];
    cell.textLabel.text = @"账户明细";
    cell.detailTextLabel.text = @"查看记录";
    cell.accessoryType = YES;
    }
    if (indexPath.row == 1) {
      
        cell.imageView.image = [UIImage imageNamed:@"account_my_market.png"];
        cell.textLabel.text = @"我的加息卷";
        
        if ([self.mutableArray_dataForTableView count] >0) {
            
            cell.detailTextLabel.text =  [NSString stringWithFormat:@"有%@张加息卷",self.mutableArray_dataForTableView[1]];
        }else  {
            
            cell.detailTextLabel.text= @"有0张加息卷";
        }
        
    }
    if (indexPath.row == 2) {
        
        cell.imageView.image = [UIImage imageNamed:@"account_integral.png"];
        cell.textLabel.text = @"总积分";
        
        
        if ([self.mutableArray_dataForTableView count] >0) {
            
            cell.detailTextLabel.text =  [NSString stringWithFormat:@"%@分",self.mutableArray_dataForTableView[2]];
        }else  {
            
            cell.detailTextLabel.text = @"0分";
        }
        
    }
    return cell;
}

#pragma mark - rightButtonAction
- (void)rightButtonAction{
    
    SafeCentreViewController *safeVC = [[SafeCentreViewController alloc]init];
    [safeVC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:safeVC animated:YES];
}
#pragma mark -tapAcion
- (void)tapGestureHandle:(UITapGestureRecognizer *)tap {
    switch (tap.view.tag) {
        case 400: //年化收益
        {
            IncomeViewController *incomeVC= [[IncomeViewController alloc] init];
            [incomeVC setStr_totayProfit:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"totalPayoff"]]];
            [incomeVC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController: incomeVC animated:YES];
        }
            break;
        case 401: //收益明细
        {
            IncomeViewController *incomeVC= [[IncomeViewController alloc] init];
            [incomeVC setStr_totayProfit:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"totalPayoff"]]];
            [incomeVC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController: incomeVC animated:YES];
        }
            break;
            
        default:
            break;
    }

}
#pragma mark -didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        AssetDetailsViewController *assetDetailVC = [[AssetDetailsViewController alloc]init];
        [assetDetailVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:assetDetailVC animated:YES];
    }
    if (indexPath.row == 1) {

        self.tabBarController.selectedIndex = 1;
    }
    if (indexPath.row == 2) { //跳转从积分历史记录到兑换加息券列表TicketExcahngeAndSigningController
        
        TicketExcahngeAndSigningController *exchangeVC = [[TicketExcahngeAndSigningController alloc]init];
        [exchangeVC setType:@"ticket"];
        [exchangeVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:exchangeVC animated:YES];
    }
}
#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {
    
    // 禁用主界面的返回按钮
    [self.navigationItem setLeftBarButtonItem:nil];
    [self.navigationItem setTitle:@"我的帐户"];
    
    [self setRightBarButtonItemTitle:@"安全中心" imageName:@"safe" actionName:@selector(rightButtonAction)];
//    self.array_assetText = @[@"今日预期收益 (元)" , @"可用余额 (元)" , @"累计收益 (元)" , @"冻结金额 (元)"];
    
    UIView *view_red = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, MULTIPLYHEIGHT(120))];
    [view_red.layer setContents:(__bridge id)[UIImage imageNamed:@"wave"].CGImage];
    [view_red setTag:49];
    
    [self.view addSubview:view_red];
    
    UILabel *label_userPhoneNumber = [[UILabel alloc]initWithFrame:CGRectMake( MULTIPLYWIDTH(88.0), MULTIPLYHEIGHT(10.0), MULTIPLYWIDTH(200.0), MULTIPLYHEIGHT(19.0))];
    NSString *str_userPhoneNumber = GETCURRENTUSERINOBYPRAMETERES(user_userName);
    label_userPhoneNumber.text = [NSString stringWithFormat:@"亲爱的用户: %@,您好!",str_userPhoneNumber];
    label_userPhoneNumber.textColor = [UIColor whiteColor];
    label_userPhoneNumber.layer.borderWidth = 1;
    label_userPhoneNumber.layer.cornerRadius = 10;
    label_userPhoneNumber.font = [UIFont systemFontOfSize:11.0];
    label_userPhoneNumber.layer.borderColor = [UIColor whiteColor].CGColor;
    label_userPhoneNumber.adjustsFontSizeToFitWidth = YES;
    label_userPhoneNumber.textAlignment = NSTextAlignmentCenter;
    [label_userPhoneNumber setTag:51];
    [view_red addSubview:label_userPhoneNumber];
    
    UILabel *label_totalAssetsText = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(139), CGRectGetMaxY(label_userPhoneNumber.frame) + MULTIPLYHEIGHT(15), MULTIPLYWIDTH(95), MULTIPLYWIDTH(15))];
    label_totalAssetsText.text = @"账户总资产(元)";
    label_totalAssetsText.textColor = [UIColor whiteColor];
    label_totalAssetsText.adjustsFontSizeToFitWidth = YES;
    label_totalAssetsText.textAlignment = NSTextAlignmentCenter;
    label_totalAssetsText.font = [UIFont systemFontOfSize:15];
    [view_red addSubview:label_totalAssetsText];
    
    UILabel *label_toatalAsstsNumber = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(107), CGRectGetMaxY(label_totalAssetsText.frame) + MULTIPLYHEIGHT(14),  MULTIPLYWIDTH(165), MULTIPLYHEIGHT(40))];
    label_toatalAsstsNumber.textAlignment = NSTextAlignmentCenter;
    label_toatalAsstsNumber.text = @"0.00";
    [label_toatalAsstsNumber setTag:50];
    
    label_toatalAsstsNumber.adjustsFontSizeToFitWidth = YES;
    label_toatalAsstsNumber.textColor = [UIColor whiteColor];
    label_toatalAsstsNumber.font = [UIFont systemFontOfSize:40];
    [view_red addSubview:label_toatalAsstsNumber];
    
    UIView *view_gray = [[UIView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(view_red.frame) + MULTIPLYHEIGHT(20), self.view.frame.size.width - MULTIPLYWIDTH(30), MULTIPLYHEIGHT(172))];
    view_gray.backgroundColor = BASECOLOR;
    [self.view addSubview:view_gray];
    
    // 竖 && 横白线
    
    UIView *view_vertical =  [UsefulUtil viewCreationWithFrame:CGRectMake(MULTIPLYWIDTH(345.0/2), 0, MULTIPLYWIDTH(2.0/2), MULTIPLYHEIGHT(380.0/2)) backgroundColor:[UIColor whiteColor] backGroundImage:nil];
    
    UIView *view_horizon = [UsefulUtil viewCreationWithFrame:CGRectMake(0, MULTIPLYHEIGHT(188.0/2), view_gray.bounds.size.width, MULTIPLYHEIGHT(2.0/2)) backgroundColor:[UIColor whiteColor] backGroundImage:nil];
    
    [view_gray addSubview:view_horizon];
    [view_gray addSubview:view_vertical];
    
    // 具体内容 ， 这儿想办法用模余算法弄成for-in,中间多了个白线，so 暂时不用
    
    WalletCenterView *view_content1 = [[WalletCenterView alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"今日预期收益 (元)" rate:GETCURRENTUSERINOBYPRAMETERES(user_userdayWalletProfit) isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:YES]];
    view_content1.tag = 400;
    [view_content1 setDelegate:self];
    
    [view_gray addSubview:view_content1];
    
    WalletCenterView *view_content2 = [[WalletCenterView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_vertical.frame), 0, MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"累计收益 (元)" rate:GETCURRENTUSERINOBYPRAMETERES(user_userEarnings) isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:YES]];
    [view_content2 setDelegate:self];
    view_content2.tag = 401;
    [view_gray addSubview:view_content2];
    
    WalletCenterView *view_content3 = [[WalletCenterView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_horizon.frame), MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"可用余额 (元)" rate:GETCURRENTUSERINOBYPRAMETERES(user_userAssetFree) isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:NO]];
    [view_content3 setDelegate:self];
    view_content3.tag = 402;
    [view_gray addSubview:view_content3];
    
    WalletCenterView *view_content4 = [[WalletCenterView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_vertical.frame), CGRectGetMaxY(view_horizon.frame), MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"冻结金额" rate:GETCURRENTUSERINOBYPRAMETERES(user_userAssetFrozen) isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:NO]];
    [view_content4 setDelegate:self];
    view_content4.tag = 403;
    [view_gray addSubview:view_content4];
    
//    // 作死的写法
//    for ( UIView *tmp in view_gray.subviews) {
//        
//        if ([tmp isMemberOfClass:[WalletCenterView class]]) {
//            
//            self.defaultTag ++;
//            [tmp setTag:self.defaultTag];
//        }
//    }

    UIButton *button_deposit = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *button_roolOut = [UIButton buttonWithType:UIButtonTypeSystem];
    button_deposit.frame = CGRectMake(MULTIPLYWIDTH(15),CGRectGetMaxY(view_gray.frame) + MULTIPLYHEIGHT(30)  , MULTIPLYWIDTH(165), MULTIPLYHEIGHT(45));
    [button_deposit addTarget:self action:@selector(depositAcion) forControlEvents:UIControlEventTouchUpInside];
    [button_roolOut addTarget:self action:@selector(rollOutAcion) forControlEvents:UIControlEventTouchUpInside];
    button_roolOut.frame = CGRectMake(MULTIPLYWIDTH(15) + CGRectGetMaxX(button_deposit.frame),CGRectGetMinY(button_deposit.frame) , MULTIPLYWIDTH(165), MULTIPLYHEIGHT(45));
    
    [button_deposit setTitle:@"存入" forState:UIControlStateNormal];
    button_deposit.backgroundColor = [UsefulUtil colorWithHexString:@"Fb4747"];
    button_deposit.tintColor = [UIColor whiteColor];
    button_deposit.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [button_roolOut setTitle:@"转出" forState:UIControlStateNormal];
    button_roolOut.backgroundColor = [UsefulUtil colorWithHexString:@"Fb4747"];
    button_roolOut.tintColor = [UIColor whiteColor];
    button_roolOut.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [self.view addSubview:button_deposit];
    
    [self.view addSubview:button_roolOut];
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(button_deposit.frame) + MULTIPLYHEIGHT(20), self.view.frame.size.width, MULTIPLYHEIGHT(145)) style:UITableViewStyleGrouped];
    self.tableView = tableView;
    [self.view addSubview:tableView];
    
    UIView *view_Header = [[UIView alloc]initWithFrame:CGRectMake(0, 34, 0, MULTIPLYHEIGHT(1))];
    
    [tableView setTableHeaderView:view_Header];
    tableView.delegate = self;
    tableView.dataSource = self;
    //  tableView.scrollEnabled =NO; //设置tableview 不能滚动
    
    // 初始化数据源
    
    self.mutableArray_dataForTableView = [NSMutableArray array];
    self.mutableDictionary_data = [NSMutableDictionary dictionary];
}


- (void) setRightBarButtonItemTitle:(NSString *) title imageName:(NSString *) name actionName:(SEL)action {
    
    // 图片在前，文字在后
    
    UIButton *button_rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(180.0/2), MULTIPLYHEIGHT(44.0))];
    [button_rightItem setTitle:title forState:UIControlStateNormal];
    [button_rightItem setTitleColor:[UsefulUtil colorWithHexString:@"#fb4747"] forState:UIControlStateNormal];
    [button_rightItem.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [button_rightItem addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    
    // 图片
    CALayer *layer_icon = [CALayer layer];
    
    [layer_icon setFrame:CGRectMake(0,MULTIPLYHEIGHT(31.0/2), MULTIPLYWIDTH(26.0/2), MULTIPLYHEIGHT(26.0/2))];
    [button_rightItem.layer addSublayer:layer_icon];
    
    
    [layer_icon setContents:(__bridge id)[UIImage imageNamed:name].CGImage];
    [button_rightItem setTitleEdgeInsets:UIEdgeInsetsMake(0, MULTIPLYWIDTH(8.0), 0, 0)];
    [button_rightItem.titleLabel setAdjustsFontSizeToFitWidth:YES];
    [button_rightItem.titleLabel setTextAlignment:NSTextAlignmentRight];
    UIBarButtonItem *barItemRight = [[UIBarButtonItem alloc] initWithCustomView:button_rightItem];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    /**
     *  width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和边界间距为5pix，所以width设为-5时，间距正好调整
     *  为0；width为正数时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacer.width = MULTIPLYWIDTH(-15.0);
    [self.navigationItem setRightBarButtonItems:@[negativeSpacer,barItemRight]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
